package netbar.user.dao;

import netbar.user.entity.User;

public class UserDaoImpl implements UserDao {
    public User getUserByCard_no(String userName) {
        User user = null;
        try {
            Connection conn = ConnManager.getConnection();
            String sql = "select * from user where card_no=?";
            PreparedStatement pst = conn.prepareStatement(sql);
            pst.setString(1, userName);
            ResultSet rs = pst.executeQuery();
            if (rs.next()){
                user = new User();
				/*
				private String card_no;//卡号（主键）
				private String password;//密码
				private String user_no;//身份证号
				private String user_name;//用户名
				private String level;//级别
				private String user_balance;//用户余额
				private String computer_no;//分配电脑

				*/
                user.setCard_no(rs.getString("card_no"));
                user.setPassword(rs.getString("password"));
                user.setUser_no(rs.getString("user_no"));
                user.setUser_name(rs.getString("user_name"));
                user.setLevel(rs.getString("level"));
                user.setUser_balance(rs.getString("user_balance"));
                user.setComputer_no(rs.getString("computer_no"));

            }else{
                //如果数据库没有对应的记录，把user定义为null
                user =null;
            }
            rs.close();
            pst.close();
            conn.close();
            return user;
        } catch (Exception e) {
            System.out.println("数据库访问有异常："+e.getMessage());
            return null;
        }

    }
}
